package com.gxa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.base.RespResult;
import com.gxa.domain.dto.RolePageDto;
import com.gxa.domain.entity.Role;
import com.gxa.mapper.RoleMapper;
import com.gxa.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 万事顺意
 * Created with IntelliJ IDEA.
 * User: zwj
 * Date: 2024/07/1716:24
 * Description:
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Autowired
    private RoleMapper roleMapper;
    @Override
    public RespResult searchRole(RolePageDto dto){
        Page<Role> page= new Page<>(dto.getPage(), dto.getLimit());
        QueryWrapper<Role> queryWrapper= new QueryWrapper<>();
        if (dto.getRoleName()!=null && !dto.getRoleName().isEmpty()){
            queryWrapper.like("role_name",dto.getRoleName());
        }
        Page<Role> result= roleMapper.selectPage(page, queryWrapper);
        long total= result.getTotal();
        List<Role> records= result.getRecords();
        return RespResult.success(records,total);
    }
}

